<template>
  <div class="classification flowCloumn h100">
    <div class="constentmain h100">
      <listTableNew v-bind="tableSetting" ref="klTable"></listTableNew>
    </div>
  </div>
</template>
<script>
import {
  getListApi //列表
} from "@/api/orderManagement/classification";
export default {
  components: {},
  props: {
    menuType: {
      type: String,
      default: "electrical"
    }
  },
  data() {
    return {
      pageType: "list",
      formData: {},
      currentDevice: {},
      tableSetting: {
        // selectionShow: true,
        showCustomBtn: true,
        showFilterBtn: true,
        pageConfig: {
          pageCode: "defectOrder", //页面标识，用来存储过滤器以及自定义列的时候用
          userId: this.$store.getters.userInfo.id
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
            type: ""
            // type:this.menuType
          },
          searchArr: [
            {
              type: "input",
              label: "标题",
              model: "title"
            },
            {
              type: "input",
              label: "分级分项名称",
              model: "name"
            },
            {
              type: "input",
              label: "大修工单编号",
              model: "orderCode"
            },
            {
              label: "状态",
              model: "status",
              type: "select",
              // multiple: true,
              option: this.$store.getters["dirtData"]("order_grade_status")
            },
            {
              type: "input",
              label: "验收单编号",
              model: "code"
            },
            {
              label: "专业",
              model: "majorList",
              type: "select",
              multiple: true,
              option: this.$store.getters["dirtData"]("common_major")
            },
            {
              type: "userOnly",
              label: "现场负责人",
              model: "joberName",
              idsStr: "jober",
              placeholder: "请输入"
            },
            {
              type: "userOnly",
              label: "当前处理人",
              model: "curNodeUserNames",
              idsStr: "curNodeUser",
              placeholder: "请输入"
            }
          ]
        },
        actionList: [],
        column: [
          {
            label: "状态",
            prop: "status",
            formatter: row => {
              return this.$store.getters["fineDirtDataName"](
                "order_grade_status",
                row.status
              );
            },
            sortable: "custom",
            width: "110px"
          },
          {
            label: "编号",
            prop: "code",
            sortable: "custom",
            showTooltip: true,
            width: "200px"
          },
          {
            label: "标题",
            prop: "title",
            sortable: "custom",
            showTooltip: true,
            width: "320px"
          },
          {
            label: "分级分项名称",
            prop: "name",
            sortable: "custom",
            minWidth: "250px"
          },
          {
            label: "专业",
            prop: "major",
            formatter: row => {
              return this.$store.getters["fineDirtDataName"](
                "common_major",
                row.major
              );
            },
            sortable: "custom",
            minWidth: "80px"
          },
          {
            label: "现场负责人",
            prop: "joberName",
            sortable: "custom",
            minWidth: "120px"
          },
          {
            label: "大修工单编号",
            prop: "orderCode",
            sortable: "custom",
            minWidth:"180px",
          },
          {
            label: "当前审批节点",
            prop: "curNodeName",
            sortable: "custom",
            showTooltip: true,
            minWidth:"180px",
          },
          {
            label: "当前处理人",
            prop: "curNodeUserNames",
            sortable: "custom",
            showTooltip: true,
            minWidth:"180px",
          },
          
        ],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: val => {
            this.gotoDetails(val);
          }
        }
      }
    };
  },
  watch: {
    menuType(val) {
      this.init();
    }
  },
  computed: {},
  created() {
    /* 添加监听事件 */
    window.addEventListener("storage", this.updateData);
  },
  beforeDestroy() {
    /* 删除监听事件 */
    window.removeEventListener("storage", this.updateData);
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.pageType = "edit";
      this.$refs.klTable.getTableConfig(); //需要显示过滤器以及自定义列时要提前调用,不需要过滤器时不调用
      setTimeout(() => {
        this.updateData();
      }, 1000);
    },
    updateData() {
      this.$refs.klTable.searchData();
    },
    getTableData(params, sortStr) {
      let form = { ...params };
      form.type = this.menuType;
      if (sortStr) {
        form.orders = sortStr;
      }
      getListApi(form)
        .then(res => {
          let data = res.data.list || [];
          let total = res.data.total || 0;
          this.$set(this.tableSetting, "tableData", data);
          this.$set(this.tableSetting, "totalNumber", total);
        })
        .catch(e => {
          this.$set(this.tableSetting, "tableData", []);
          this.$set(this.tableSetting, "totalNumber", 0);
        });
    },
    //打开详情页
    gotoDetails(data) {
      if (data) {
        this.pageType = "edit";
      }
      let form = {
        pageType: this.pageType
      };
      if (this.pageType != "add") {
        form.id = data.id;
      }
      let { href } = this.$router.resolve({
        path: "/orderManagement/classification/details",
        query: form
      });
      window.open(href, "_blank");
    }
  }
};
</script>
<style lang="less" scoped>
.classification {
  min-height: 500px;
  height: 100%;
}
</style>